package com.woniuxy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.mapper.GoodsShowMapper;
import com.woniuxy.service.GoodsShowService;
import com.work.framework.pojo.Goods;
import com.work.framework.pojo.GoodsAuctionDTO;
import org.apache.ibatis.annotations.Select;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author fengyao
 * @version 1.0
 * @date 2019/9/20 0020 上午 12:34
 */
@Service
//@EnableCaching
public class GoodShowServiceImpl implements GoodsShowService {

    @Resource
    GoodsShowMapper goodsShowMapper;
    /**
     * 需要获取四种商品类型中收藏前五的商品
     * @return
     */
    @Override
//    @Cacheable(value="goodsShow",keyGenerator = "myKeyGenerator")
    public Map selectHotGoodsByClassify() {
        //Goods+Auction
        //通过cid查询goods（List）-- Auction
        //链表查询
        //Goods-Auction
        List<GoodsAuctionDTO> hotGoods = goodsShowMapper.selectHotGoodsByClassify(0,4, true);
        List<GoodsAuctionDTO> pcGoods = goodsShowMapper.selectHotGoodsByClassify(1, 4, true);
        List<GoodsAuctionDTO> mobileGoods = goodsShowMapper.selectHotGoodsByClassify(2, 4, true);
        List<GoodsAuctionDTO> cameraGoods = goodsShowMapper.selectHotGoodsByClassify(3, 4, true);
        List<GoodsAuctionDTO> otherGoods = goodsShowMapper.selectHotGoodsByClassify(4, 4, true);
        HashMap<String,List<GoodsAuctionDTO>> hashMap = new HashMap<String,List<GoodsAuctionDTO>>();
        hashMap.put("hotGoods",hotGoods);
        hashMap.put("pcGoods",pcGoods);
        hashMap.put("mobileGoods",mobileGoods);
        hashMap.put("cameraGoods",cameraGoods);
        hashMap.put("otherGoods",otherGoods);
        return hashMap;
    }

    /**
     * 查询热点商品
     * @return
     */
    @Override
//    @Cacheable(value="goodsShow",keyGenerator = "myKeyGenerator")
    public Map<String, List<GoodsAuctionDTO>> selectHotGoodsByStatus() {
        HashMap<String,List<GoodsAuctionDTO>> hashMap=new  HashMap<String,List<GoodsAuctionDTO>>();
        List<GoodsAuctionDTO> noAuction = goodsShowMapper.selectHotGoodsByStatus(3, 4, true);
        List<GoodsAuctionDTO> auctioning = goodsShowMapper.selectHotGoodsByStatus(4, 4, true);
        hashMap.put("auctioning",auctioning);
        hashMap.put("noAuction",noAuction);
        return hashMap;
    }

    /**
     * shop列表
     * @param countyid 城市id
     * @param cid 商品类别
     * @param sortType 排序类型
     * @param sort 正序倒序
     * @param name 模糊查询
     * @param pageNum 页码
     * @param pageSize 页面大小
     * @return
     */
    @Override
//    @Cacheable(value="goodsShow",keyGenerator = "myKeyGenerator")
    public List<GoodsAuctionDTO> selectGoodsListToPage(Integer countyid,Integer cid, String sortType, Integer sort,String name,Integer pageNum,Integer pageSize) {
        System.out.println("pageNum="+pageNum);
        PageHelper.startPage(pageNum,pageSize);
        List<GoodsAuctionDTO> goodsAuctionDTOS = goodsShowMapper.selectGoodsList(countyid,cid, sortType, sort,name);
        PageInfo<GoodsAuctionDTO> pageInfo=new PageInfo<>(goodsAuctionDTOS);
        return goodsAuctionDTOS;
    }

    /**
     * 查询收藏商品
     * @param pageNum 当前页码
     * @param pageSize 页面大小
     * @param uid 个人Id
     * @return goods.gid
     */
    @Override
//    @Cacheable(value="goodsShow",key="#goodsAuctionDTOS.")
    public List<GoodsAuctionDTO> selectEnshrineGoods(Integer pageNum, Integer pageSize, Integer uid) {
        PageHelper.startPage(pageNum,pageSize);
        List<GoodsAuctionDTO> goodsAuctionDTOS = goodsShowMapper.selectEnshrineGoods(uid);
        System.out.println(goodsAuctionDTOS);
        return goodsAuctionDTOS;
    }

    /**
     * 查询我的商品
     * @param uid 用户id
     * @return 返回我的拍卖品
     */
    @Override
//    @Cacheable(value="goodsShow",keyGenerator = "myKeyGenerator")
    public List<GoodsAuctionDTO> selectGoodsMyGoods(Integer uid) {
        List<GoodsAuctionDTO> goodsAuctionDTOS = goodsShowMapper.selectGoodsMyGoods(uid);
        return goodsAuctionDTOS;
    }

    /**
     * 按照金钱查询
     * @param min 最小值
     * @param max 最大值
     * @return
     */
    @Override
//    @Cacheable(value="goodsShow",keyGenerator = "myKeyGenerator")
    public List<GoodsAuctionDTO> selectGoodsByMoney(Integer min, Integer max) {
        List<GoodsAuctionDTO> goodsAuctionDTOS = goodsShowMapper.selectGoodsByMoney(min, max);
        return goodsAuctionDTOS;
    }

}
